package copyengine.dataLayer.query.database
{
	import copyengine.dataLayer.query.local.CELocalQueryExcuteManger;
	import copyengine.utils.UUIDFactory;

	public class CEMacroDatabaseQueryImpl extends CEDatabaseQueryBasic
	{

		public function CEMacroDatabaseQueryImpl(_name:String, _param:Object, _localDatabase:ICEDatabase)
		{
			super(_name, _param, _localDatabase);
		}

		override public function onRegister():void
		{
			if (isCanGetDataFromLocalDatabase())
			{
				finishDatabaseQuery();
			}
			else
			{
				CELocalQueryExcuteManger.instance.excuteLocalQuery(onFinished, UUIDFactory.instance.generateUUID(), getSubDatabaseQueryList())
			}
		}

		private function onFinished(_result:Object):void
		{
			onAllSubQueryFinishd(_result);
			finishDatabaseQuery();
		}

		protected function onAllSubQueryFinishd(_result:Object):void
		{
			throw new Error("child class should override this function");
		}

		protected function getSubDatabaseQueryList():Array
		{
			throw new Error("child class should override this function");
		}

		protected function isCanGetDataFromLocalDatabase():Boolean
		{
			throw new Error("child class should override this function");
		}

	}
}